// https://leetcode.cn/problems/swap-nodes-in-pairs/

class Solution
{
public:
    // 每个dfs做的事：交换当前节点与下一个节点，并返回交换后的头节点

    struct ListNode *swapPairs(struct ListNode *head)
    {
        if (!head || !head->next)
            return head;
        struct ListNode *tmp = swapPairs(head->next->next);
        struct ListNode *newhead = head->next;
        newhead->next = head;
        head->next = tmp;
        return newhead;
    }
};